#ifndef TURNCONTROLLER_H
#define TURNCONTROLLER_H

#include <QWidget>
#include <QPoint>
#include <QRect>

class TurnController : public QWidget
{
    Q_OBJECT
public:
    explicit TurnController(QWidget *parent = nullptr);
    void startDragging(const QPoint& pos);
    
    double getTurnSpeed() const { return m_turnSpeed; }

signals:
    void turnChanged(double x);

protected:
    bool event(QEvent *event) override;
    void paintEvent(QPaintEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

private:
    bool m_isDragging = false;
    QPoint m_currentPos;
    QPoint m_center;
    QRect m_controlRect;
    int m_radius;
    double m_turnSpeed = 0.0;
    
    void calculateTurn(const QPoint& pos);
    QPoint limitToRect(const QPoint& pos);
    void drawBackground(QPainter& painter);
    void drawCenterPoint(QPainter& painter);
};

#endif // TURNCONTROLLER_H 